<template>
  <view
    class="SearchDiscussionItem animate__animated animate__bounceInRight"
    @click="skipToDiscussion"
  >
    <view class="left">
      <view class="title">{{ discussionDetail.title }}</view>
      <view class="footer">
        <view class="info">
          <view class="time">{{
            $formatTime.formatTime(discussionDetail.createTime)
          }}</view>
          <view class="categary">{{ discussionDetail.categary }}</view>
        </view>
        <view class="operator">
          <view class="opeartor-item">
            <image src="../../static/icons/comment.png" class="icon"></image>
            <text>{{ discussionDetail.commentList.length }}</text>
          </view>
          <view class="opeartor-item">
            <image src="../../static/icons/like.png" class="icon"></image>
            <text>{{ discussionDetail.liked }}</text>
          </view>
        </view>
      </view>
    </view>
    <view class="right">
      <image
        :src="
          discussionDetail.picList.length
            ? discussionDetail.picList[0]
            : discussionDetail.author.avatar
        "
        class="avatar"
      ></image>
    </view>
  </view>
</template>

<script>
export default {
  name: "SearchDiscussionItem",
  props: {
    discussionDetail: {
      type: Object,
    },
  },
  data() {
    return {};
  },
  methods: {
    skipToDiscussion() {
      const id = this.discussionDetail._id;
      // 先将残留内容清空
      this.$store.commit("m_discussion/clearCurrentDiscussion");
      uni.navigateTo({
        url: `../../pages/Discussion/Discussion?id=${id}`,
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.SearchDiscussionItem {
  display: flex;
  box-sizing: border-box;
  padding: 20rpx 0;
  border-bottom: 1rpx solid #eee;
  .left {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    .title {
      width: 100%;
      text-overflow: ellipsis;
      overflow: hidden;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      font-size: 34rpx;
    }
    .footer {
      display: flex;
      justify-content: space-between;
      align-items: center;
      color: #aaa;
      font-size: 24rpx;
      .info {
        display: flex;
        align-items: center;
        .categary {
          margin-left: 10rpx;
        }
      }
      .icon {
        width: 30rpx;
        height: 30rpx;
        margin-right: 5rpx;
      }
      .operator {
        display: flex;
        align-items: center;
        .opeartor-item {
          display: flex;
          align-items: center;
          margin-left: 10rpx;
        }
      }
    }
  }
  .right {
    width: 210rpx;
    height: 140rpx;
    margin-left: 20rpx;
    border-radius: 7rpx;
    overflow: hidden;
    .avatar {
      width: 100%;
      height: 100%;
    }
  }
}
</style>
